package com.gimi.cloud.bbp.manage.consumer.service.impl;

import com.gimi.cloud.bbp.common.enums.ResponseCodeEnum;
import com.gimi.cloud.bbp.common.utils.StringUtil;
import com.gimi.cloud.bbp.common.utils.reqhead.Response;
import com.gimi.cloud.bbp.dto.params.LoginParams;
import com.gimi.cloud.bbp.dto.sys.SysMasterDTO;
import com.gimi.cloud.bbp.manage.consumer.feign.SystemFeignService;
import com.gimi.cloud.bbp.manage.consumer.service.LoginService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 系统登录相关服务
 * @author wbj
 * @version 1.0
 * @Description
 * @create 2017-12-20
 **/
@Service
public class LoginServiceImpl implements LoginService {
    private static final Logger logger = LoggerFactory.getLogger(LoginServiceImpl.class);
    private SystemFeignService systemFeignService;
    @Autowired
    public LoginServiceImpl(SystemFeignService systemFeignService) {
        this.systemFeignService = systemFeignService;
    }

    @Override
    public Response login(HttpServletRequest request, HttpServletResponse response, LoginParams param) throws Exception {
        Response resp = null;
        if(StringUtil.isAnyBlank(param.getValidateKey(),param.getValidateCode())){
            resp =  new Response();
            resp.setResponseCode(ResponseCodeEnum.PARAMETER_ERROR);
            resp.setRes_msg("验证码错误");
            return resp;
        }
        if(StringUtil.isAnyBlank(param.getUsername(),param.getUsername())){
            resp =  new Response();
            resp.setResponseCode(ResponseCodeEnum.PARAMETER_ERROR);
            resp.setRes_msg("用户名密码不能为空");
            return resp;
        }
       return systemFeignService.masterLogin(param);
    }

    @Override
    public Response logout(HttpServletRequest request, HttpServletResponse response, SysMasterDTO masterDTO) throws Exception {
        return systemFeignService.masterLogout(masterDTO);
    }
}
